#!/usr/bin/env python3
"""
Simple PyInstaller build script for Ollama Translator
"""

import os
import sys
import subprocess
from pathlib import Path


def main():
    print("Building Ollama Translator executable...")
    
    # Check if PyInstaller is available
    try:
        import PyInstaller
    except ImportError:
        print("PyInstaller not found. Installing...")
        subprocess.check_call([sys.executable, "-m", "pip", "install", "pyinstaller"])
    
    # Build command
    cmd = [
        sys.executable, "-m", "PyInstaller",
        "--name=ollama_translate",
        "--onefile",
        "--noconsole",
        "--add-data=README.md:.",
        "--hidden-import=config_manager",
        "--hidden-import=ollama_client", 
        "--hidden-import=translator_gui",
        "--hidden-import=config_window",
        "main.py"
    ]
    
    print("Running:", " ".join(cmd))
    
    try:
        result = subprocess.run(cmd, check=True)
        print("\n✓ Build successful!")
        print("Executable location: dist/ollama_translate")
        
        # Make executable
        exe_path = Path("dist/ollama_translate")
        if exe_path.exists():
            exe_path.chmod(0o755)
            print(f"File size: {exe_path.stat().st_size / (1024*1024):.1f} MB")
        
    except subprocess.CalledProcessError as e:
        print(f"\n✗ Build failed: {e}")
        sys.exit(1)


if __name__ == "__main__":
    main()